

import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sph_driver/AppConfig/ShowDialog.dart';
import 'package:sph_driver/Authentication/IDCard.dart';
import 'package:sph_driver/Main/CustomerService/ModifyPhoneNumber.dart';
import 'package:sph_driver/Main/EditInformation/EditCarCard.dart';
import 'package:sph_driver/Main/EditInformation/EditDriverCard.dart';
import 'package:sph_driver/Main/EditInformation/EditIDCard.dart';
import 'package:sph_driver/Main/EditInformation/EditQualification.dart';
import 'package:sph_driver/Main/EditInformation/EditRoadCard.dart';
import 'package:sph_driver/Main/EditInformation/EditTrailerCard.dart';
import 'package:sph_driver/http/NoLoadingPostApi.dart';

import '../AppConfig/Config.dart';
import '../AppConfig/LocalStorage.dart';
import '../AppConfig/RouteAct.dart';
import '../AppConfig/StringEncapsulation.dart';
import '../http/NoLoadingGetApi.dart';
import '../http/api.dart';
import '../l10n/messages.dart';
import 'package:image/image.dart' as img;

import 'FleetManagement/FleetManagement.dart';
import 'FleetManagement/MyFleet.dart';
class InformationView extends StatefulWidget {
  const InformationView({super.key, required this.dataMap, required this.isAdd});
  final Map dataMap;
  final bool isAdd;
  @override
  State<InformationView> createState() => _InformationViewState();
}

class _InformationViewState extends State<InformationView> {
  final ImagePicker picker = new ImagePicker();
  File? _userImage;
  Map userMap={};
  String headPath="";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // userMap=widget.dataMap;
    getUserMessage();
  }

  void getUserMessage() async {
    NoLoadinggetApiManager.getData(
      context, // 上下文对象，用于显示提示信息等
      'api/auth/driver/user/getLoginUser', // 您的API端点
      {}, // 查询参数，如果没有可以传递null
          (responseData)  {
        setState(() {
          userMap=responseData['data'];
        });
      },
    );
  }
//获取图片路径
  Future<void> uploadSingleFile(String fileData) async {
    String? drvId =await UserIdManager.getUserID();
    NoLoadingApiManager.postData(
      context,
      'api/system/dev/file/uploadSingleFile',
      {
        "type":"DriverAvatar",
        "typeKey":drvId,
        "fileData":fileData,
        "fileFormat":"jpg"
      },
          (responseData) {
        setState(() {
          headPath=responseData['data'].toString();
          upLoadHeadPic();
        });
      },
    );

  }

  Future<void> upLoadHeadPic() async {
    String? userId= await UserIdManager.getUserID();
    ApiManager.postData(
      context,
      'api/auth/driver/user/editAvatar',
      {
        "userId":userId,
        "avatarPath":headPath,
      },
          (responseData) {
        setState(() {
          BrnToast.show("提交成功", context);
        });
      },
    );

  }

  String imageToBase64(File imageFile) {
    List<int> imageBytes = imageFile.readAsBytesSync();
    String base64String = base64Encode(Uint8List.fromList(imageBytes));

    return base64String;
  }


  void printImageMemorySize(File imageFile) {
    List<int> imageBytes = imageFile.readAsBytesSync();
    print('Original Image Memory Size: ${imageBytes.length} bytes');
  }

  Future<void> compressImage(File imageFile) async {
    List<int> imageBytes = await imageFile.readAsBytes();
    img.Image image = img.decodeImage(Uint8List.fromList(imageBytes))!;

    // Adjust the quality and size as needed
    img.Image compressedImage = img.copyResize(image, width: 1024);

    List<int> compressedBytes = img.encodeJpg(compressedImage, quality: 80);

    // Create a new File for the compressed image
    File compressedFile = File('${imageFile.path}_compressed.jpg');
    await compressedFile.writeAsBytes(compressedBytes);

    print('Compressed Image Size: ${compressedBytes.length} bytes');

    convertToBase64(compressedFile);
  }

  Future<void> convertToBase64(File imageFile) async {
    List<int> imageBytes = await imageFile.readAsBytes();
    String base64String = base64Encode(imageBytes);
    uploadSingleFile(base64String);

  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    var messages = AppLocalizations.of(context)!;
    return Scaffold(
      backgroundColor: Color.fromRGBO(248, 248, 248, 1),
      appBar: AppBar(
        backgroundColor: Color.fromRGBO(231, 112, 27, 0.85),
        title: Text(messages["个人信息"],style: TextStyle(color: Colors.white,fontWeight: FontWeight.w300),),
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.white),
          onPressed: (){
            if(widget.isAdd){
            if(userMap['personalStatus']==2){
              Navigator.pop(context,"success");
            }else{
              Navigator.of(context).pop();
            }
            }else{
              Navigator.of(context).pop();
            }

          }
        ),
      ),
      body: userMap.isEmpty?Container(color: Colors.white,):
          Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [MyColors.themeColor,MyColors.backgreyColor, MyColors.backgreyColor,MyColors.backgreyColor], // 渐变颜色数组
                begin: Alignment.topCenter, // 渐变开始的位置
                end: Alignment.bottomCenter, // 渐变结束的位置
              ),

            ),
          child:
      ListView(
        children: [
          Container(
            height: 160.h,
            width: screenSize.width ,
            // decoration: BoxDecoration(
            //   gradient: LinearGradient(
            //     colors: [MyColors.themeColor, Colors.white], // 渐变颜色数组
            //     begin: Alignment.topCenter, // 渐变开始的位置
            //     end: Alignment.bottomCenter, // 渐变结束的位置
            //   ),
            //
            // ),
            child: Column(
              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
            child:
            Container(
              width: 60.w,
              height: 60.h,
              child: _userImage!=null?
              ClipOval(
              child: Image.file(_userImage!, width: 60.w,
                height: 60.h, fit: BoxFit.cover,),
              ):
               userMap['avatarPath']!=null&&userMap['avatarPath']!=""?
              CircleAvatar(
                radius: 15,
                backgroundImage: NetworkImage(MyServiceUrl.imgHeader +userMap['avatarPath']),
              )
                  :  CircleAvatar(
                radius: 15,
                backgroundImage: AssetImage("lib/Images/login/默认头像.jpeg"),
              ),
            ),
            // ClipOval(
            // child: _userImage==null?  Image.network(MyServiceUrl.imgHeader+userMap['avatarPath'],width: 60.w,height: 60.h,):Image.file(_userImage!, width: 60.w,
            //   height: 60.h, fit: BoxFit.cover,),
            //       ),
                  onTap: (){
                    showModalBottomSheet(context: context, builder: (BuildContext context)
                    {
                      return Container(
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10)),
                        ),
                        child:
                        Stack(

                          children: [

                            Column(
                              mainAxisSize: MainAxisSize.min,
                              mainAxisAlignment:MainAxisAlignment.center,

                              children:[

                                SizedBox(height: 8.h,),
                                Row(
                                  mainAxisAlignment:MainAxisAlignment.spaceBetween,
                                  children: [
                                    SizedBox(width: 20.w,),
                                    Text(messages["上传照片"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 18.sp),),
                                    IconButton(onPressed: (){
                                      Navigator.of(context).pop();
                                    }, icon:Icon(Icons.close,color: MyColors.textColor,size: 30,)),
                                  ],
                                ),

                                SizedBox(height: 18.h,),
                                Row(
                                  children: [
                                    SizedBox(width: 38.w,),
                                    GestureDetector(
                                      child:   Column(
                                        children: [
                                          Image.asset("lib/Images/Authentication/相册icon.png",width:35.w ,height: 35.h,),
                                          Text(messages["相册"],style: TextStyle(color: Colors.black),),

                                        ],

                                      ),
                                      onTap: ()async{

                                        var status = await Permission.photos.request();
                                        if(status==PermissionStatus.denied){
                                          showPhotosFirstDialog(context);
                                        }else if(status==PermissionStatus.permanentlyDenied){
                                          showPhotosDialog(context);
                                        }else{
                                          Navigator.of(context).pop();
                                          final pickedFile = await picker.pickImage(source: ImageSource.gallery);

                                          if (pickedFile != null) {

                                            setState(() {
                                              _userImage = File(pickedFile.path);
                                              printImageMemorySize(_userImage!);
                                              print(_userImage);
                                              compressImage(_userImage!);
                                            });
                                          }
                                        }

                                      },
                                    ),

                                    SizedBox(width: 38.w,),
                                    GestureDetector(
                                      child: Column(
                                        children: [
                                          Image.asset("lib/Images/Authentication/拍照icon.png",width:35.w ,height: 35.h,),
                                          Text(messages["拍照"],style: TextStyle(color: Colors.black),),
                                        ],
                                      ),
                                      onTap: ()async{
                                        var status = await Permission.camera.request();
                                        if(status==PermissionStatus.denied){
                                          showCameraFirstDialog(context);
                                        }else if(status==PermissionStatus.permanentlyDenied){
                                          showCameraDialog(context);
                                        }else{
                                          Navigator.of(context).pop();
                                          final pickedFile = await picker.pickImage(source: ImageSource.camera);
                                          if (pickedFile != null) {
                                            setState(() {
                                              _userImage = File(pickedFile.path);
                                              printImageMemorySize(_userImage!);
                                              print(_userImage);
                                              compressImage(_userImage!);
                                            });
                                          }

                                        }

                                      },
                                    ),
                                  ],
                                ),
                                SizedBox(height: 40.h,),
                              ],

                            ),

                          ],

                        ),
                      );
                    }
                    );
                  },
                ),

                SizedBox(height: 8.h,),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(userMap['realName']!=""&&userMap['realName']!=null?userMap['realName']:"司机",style: TextStyle(color: Colors.white,fontSize:16.sp ),),
                    SizedBox(width: 8.w,),
                    if(userMap['personalStatus']!=2)
                      BrnTagCustom.buildBorderTag(
                        tagText: '未认证',
                        textColor: Colors.white,
                        borderColor: Colors.white,
                        borderWidth: 1,
                        fontSize:9.sp,
                        textPadding: EdgeInsets.all(1),
                      ),
                    if(userMap['personalStatus']==2&&userMap['driverLicenseStatus']==2&&userMap['vehicleDrivingLicenseStatus']==2&&(userMap['qualificationCertificateStatus']!=2||userMap['roadTransportCertificateStatus']!=2))
                      BrnTagCustom.buildBorderTag(
                        tagText: '三证齐全',
                        textColor: Colors.white,
                        borderColor: Colors.white,
                        borderWidth: 1,
                        fontSize:9.sp,
                        textPadding: EdgeInsets.all(1),
                      ),
                    if(userMap['personalStatus']==2&&userMap['driverLicenseStatus']==2&&userMap['vehicleDrivingLicenseStatus']==2&&userMap['qualificationCertificateStatus']==2&&userMap['roadTransportCertificateStatus']==2)
                      BrnTagCustom.buildBorderTag(
                        tagText: '五证齐全',
                        textColor: Colors.white,
                        borderColor: Colors.white,
                        borderWidth: 1,
                        fontSize:9.sp,
                        textPadding: EdgeInsets.all(1),
                      ),
                    if(userMap['personalStatus']==2&&(userMap['driverLicenseStatus']!=2||userMap['vehicleDrivingLicenseStatus']!=2)&&(userMap['qualificationCertificateStatus']!=2||userMap['roadTransportCertificateStatus']!=2))
                    // Image.asset("lib/Images/PersonCenter/已认证标签.png",width: 44.w,height: 18.h,),
                      BrnTagCustom.buildBorderTag(
                        tagText: '已认证',
                        textColor: Colors.white,
                        borderColor: Colors.white,
                        borderWidth: 1,
                        fontSize:9.sp,
                        textPadding: EdgeInsets.all(1),
                      )
                  ],
                ),
                SizedBox(height: 8.h,),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w),
                  // height: 50.h,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [

                      Text("    "+messages["注册手机号"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                      Row(
                        children: [
                          Text(maskPhoneNumber(userMap['phoneNum']),style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                          TextButton(onPressed: (){
                            Navigator.push( context, FadeRoute(page:ModifyPhoneNumber(phoneNum: userMap['phoneNum'], userMap: userMap,)));

                          },
                              child: Text(messages["修改"],style: TextStyle(color: Color.fromRGBO(231, 112, 27, 0.85),fontWeight: FontWeight.w600),)),
                        ],
                      ),

                    ],
                  ),
                ),
                // SizedBox(height: 8.h,),


              ],
            ),
          ),
          GestureDetector(
            child: Container(
              padding: EdgeInsets.only(right: 10.w),
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              height: 40.h,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),

                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    if(userMap['role']==0&&userMap['captainId']==null)
                      Text("    "+messages["成为车队长"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    if(userMap['role']==1)
                      Text("    "+messages["我的车队"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    if(userMap['role']==0&&userMap['captainId']!=null)
                      Text("    "+messages["我的车队"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    Icon(Icons.arrow_forward_ios,color: MyColors.authTipColor,size: 16,),
                  ],
                ),
            ),
            onTap: ()async{

              if(userMap['personalStatus']!=2){
              BrnToast.show("未完成个人信息认证", context, duration: BrnDuration.short,);
              }else {

                if(userMap['role']==0&&userMap['captainId']==null) {
                final result = await Navigator.push(context, FadeRoute(page: FleetManagement(userMap: userMap,)));
                  if(result==null){
                    getUserMessage();
                  }
                }
                if(userMap['role']==1) {
                 final result = await Navigator.push(context, FadeRoute(
                      page: MyFleet(captainId: userMap['captainId'])));
                 if(result!=null){
                   getUserMessage();
                 }
                }
                if(userMap['role']==0&&userMap['captainId']!=null) {
                  final result = await Navigator.push(context, FadeRoute(
                      page: MyFleet(captainId: userMap['captainId'])));
                  if(result!=null){
                    getUserMessage();
                  }
                }

              }

            },
          ),

          SizedBox(height: 8.h,),
          GestureDetector(
            child:  Container(
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              padding: EdgeInsets.only(right: 12.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Column(
                children: [

                  SizedBox(height: 12.h,),
                  userMap['personalInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("    "+messages["身份证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                          SizedBox(width: 4.w,),
                          if(compareDateWithCurrent(userMap['personalInfo']['validTo'])=="2"||compareDateWithCurrent(userMap['personalInfo']['validTo'])=="3")
                            BrnTagCustom.buildBorderTag(
                              tagText: '即将过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(compareDateWithCurrent(userMap['personalInfo']['validTo'])=="4")
                            BrnTagCustom.buildBorderTag(
                              tagText: '已过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),

                          if(userMap['personalStatus']== 1)
                            BrnTagCustom.buildBorderTag(
                              tagText: '审核中',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(userMap['personalStatus']== 2)
                            BrnTagCustom.buildBorderTag(
                              tagText: '已认证',
                              textColor: Colors.green,
                              borderColor: Colors.green,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                        ],
                      ),

                      GestureDetector(
                        child: Text("编辑",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                        onTap: () async {
                          final result=await Navigator.push( context, FadeRoute(page:EditIDCard(dataMap: userMap,)));
                          if(result!=null){
                            getUserMessage();
                          }
                        },
                      )
                    ],
                  )
                      :Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+messages["身份证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ],
                  ),
                  SizedBox(height: 12.h,),
                  Divider(color: Color.fromRGBO(240, 240, 240, 1),),
                  SizedBox(height: 12.h,),
                  userMap['personalInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+userMap['personalInfo']['idNum'].toString(),style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    ],
                  ):
                  GestureDetector(
                    child: Container(
                      width: 200.w,
                      height: 40.h,
                      decoration: BoxDecoration(
                        color: MyColors.themeColor,
                        borderRadius: BorderRadius.all(Radius.circular(60)),
                      ),
                      child:Center(
                        child:Text("+前往实名认证",style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 14.sp),),

                      ),

                    ),
                    onTap: () async {
                      final result=await Navigator.push( context, FadeRoute(page:EditIDCard(dataMap: userMap,)));
                      if(result!=null){
                        getUserMessage();
                      }
                    },
                  ),
                  SizedBox(height: 12.h,),
                ],
              ),
            ),
            onTap: () async {
              final result=await Navigator.push( context, FadeRoute(page:EditIDCard(dataMap: userMap,)));
              if(result!=null){
                getUserMessage();
              }
            },
          ),

          SizedBox(height: 8.h,),
          GestureDetector(
            child: Container(
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              padding: EdgeInsets.only(right: 12.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Column(
                children: [
                  SizedBox(height: 12.h,),
                  userMap['driverLicenseInfo']!=null?

                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("    "+messages["驾驶证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                          SizedBox(width: 4.w,),
                          if(compareDateWithCurrent(userMap['driverLicenseInfo']['validPeriodTo'])=="2"||compareDateWithCurrent(userMap['driverLicenseInfo']['validPeriodTo'])=="3")
                            BrnTagCustom.buildBorderTag(
                              tagText: '即将过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(compareDateWithCurrent(userMap['driverLicenseInfo']['validPeriodTo'])=="4")
                            BrnTagCustom.buildBorderTag(
                              tagText: '已过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),

                          if(userMap['driverLicenseStatus']== 1)
                            BrnTagCustom.buildBorderTag(
                              tagText: '审核中',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(compareDateWithCurrent(userMap['driverLicenseInfo']['validPeriodTo'])!="4"&&userMap['driverLicenseStatus']== 2)
                            BrnTagCustom.buildBorderTag(
                              tagText: '已认证',
                              textColor: Colors.green,
                              borderColor: Colors.green,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                        ],
                      ),

                      GestureDetector(
                        child: Text("编辑",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                        onTap: () async {
                          final result=await Navigator.push( context, FadeRoute(page:EditDriverCard(dataMap: userMap,)));
                          if(result!=null){
                            getUserMessage();
                          }
                        },
                      )
                    ],
                  )
                      :Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+messages["驾驶证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ],
                  ),
                  SizedBox(height: 12.h,),
                  Divider(color: Color.fromRGBO(240, 240, 240, 1),),
                  SizedBox(height: 12.h,),
                  userMap['driverLicenseInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+userMap['driverLicenseInfo']['vehicleClass'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    ],
                  )
                      :GestureDetector(
                    child: Container(
                      width: 200.w,
                      height: 40.h,
                      decoration: BoxDecoration(
                        color: Color.fromRGBO(231, 112, 27, 0.85),
                        borderRadius: BorderRadius.all(Radius.circular(60)),
                      ),
                      child:Center(
                        child:Text("+"+messages["添加驾驶证"],style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                      ),
                    ),
                    onTap: ()async{
                      final result=await Navigator.push( context, FadeRoute(page:EditDriverCard(dataMap: userMap,)));
                      if(result!=null){
                        getUserMessage();
                      }
                    },
                  ),

                  SizedBox(height: 12.h,),
                ],
              ),
            ),
            onTap: ()async{
              final result=await Navigator.push( context, FadeRoute(page:EditDriverCard(dataMap: userMap,)));
              if(result!=null){
                getUserMessage();
              }
            },
          ),

          SizedBox(height: 8.h,),
          GestureDetector(
            onTap: ()async{
              final result=await Navigator.push( context, FadeRoute(page:EditCarCard(dataMap: userMap,)));
              if(result!=null){
                getUserMessage();
              }
            },
            child: Container(
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              padding: EdgeInsets.only(right: 12.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Column(
                children: [
                  SizedBox(height: 12.h,),
                  userMap['vehicleDrivingLicenseInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("    "+messages["行驶证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                          SizedBox(width: 4.w,),
                          if(compareDateWithCurrent(userMap['vehicleDrivingLicenseInfo']['scrapDate'])=="2"||compareDateWithCurrent(userMap['vehicleDrivingLicenseInfo']['scrapDate'])=="3")
                            BrnTagCustom.buildBorderTag(
                              tagText: '即将过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(compareDateWithCurrent(userMap['vehicleDrivingLicenseInfo']['scrapDate'])=="4")
                            BrnTagCustom.buildBorderTag(
                              tagText: '已过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),

                          if(userMap['vehicleDrivingLicenseStatus']== 1)
                            BrnTagCustom.buildBorderTag(
                              tagText: '审核中',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(userMap['vehicleDrivingLicenseStatus']== 2)
                            BrnTagCustom.buildBorderTag(
                              tagText: '已认证',
                              textColor: Colors.green,
                              borderColor: Colors.green,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                        ],
                      ),

                      GestureDetector(
                        child: Text("编辑",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                        onTap: () async {
                          final result=await Navigator.push( context, FadeRoute(page:EditCarCard(dataMap: userMap,)));
                          if(result=="success"){
                            getUserMessage();
                          }else if(result=="Navigator"){
                            final result=await Navigator.push( context, FadeRoute(page:EditTrailerCard(dataMap: userMap,)));

                            if(result!=null){
                              getUserMessage();
                            }
                          }
                        },
                      )
                    ],
                  ) :Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+messages["行驶证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ],
                  ),
                  SizedBox(height: 12.h,),
                  Divider(color: Color.fromRGBO(240, 240, 240, 1),),
                  SizedBox(height: 12.h,),
                  userMap['vehicleDrivingLicenseInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+userMap['vehicleDrivingLicenseInfo']['vehicleNum'],style: TextStyle(color: Colors.black,fontSize: 14.sp,),),
                    ],
                  ) :GestureDetector(
                    child: Container(
                      width: 200.w,
                      height: 40.h,
                      decoration: BoxDecoration(
                        color: Color.fromRGBO(231, 112, 27, 0.85),
                        borderRadius: BorderRadius.all(Radius.circular(60)),
                      ),
                      child:Center(
                        child:Text("+"+messages["添加行驶证"],style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                      ),
                    ),
                    onTap: ()async{
                      final result=await Navigator.push( context, FadeRoute(page:EditCarCard(dataMap: userMap,)));
                      if(result=="success"){
                        getUserMessage();
                      }else if(result=="Navigator"){
                        final result=await Navigator.push( context, FadeRoute(page:EditTrailerCard(dataMap: userMap,)));

                        if(result!=null){
                          getUserMessage();
                        }
                      }
                    },
                  ),

                  SizedBox(height: 12.h,),
                ],
              ),
            ),
          ),

          if(userMap['vehicleDrivingLicenseInfo']!=null&&userMap['vehicleDrivingLicenseInfo']['vehicleType'].contains("挂"))

            SizedBox(height: 8.h,),
         if(userMap['vehicleDrivingLicenseInfo']!=null&&userMap['vehicleDrivingLicenseInfo']['vehicleType'].contains("挂"))
          GestureDetector(
            onTap: ()async{
              final result=await Navigator.push( context, FadeRoute(page:EditTrailerCard(dataMap: userMap,)));
              if(result!=null){
                getUserMessage();
              }
            },
            child:
            Container(
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              padding: EdgeInsets.only(right: 12.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Column(
                children: [
                  SizedBox(height: 12.h,),
                  userMap['trailerDrivingLicenseInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("    "+messages["挂车行驶证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                          SizedBox(width: 4.w,),
                          if(compareDateWithCurrent(userMap['trailerDrivingLicenseInfo']['scrapDate'])=="2"||compareDateWithCurrent(userMap['trailerDrivingLicenseInfo']['scrapDate'])=="3")
                            BrnTagCustom.buildBorderTag(
                              tagText: '即将过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(compareDateWithCurrent(userMap['trailerDrivingLicenseInfo']['scrapDate'])=="4")
                            BrnTagCustom.buildBorderTag(
                              tagText: '已过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),

                          if(userMap['trailerDrivingLicenseStatus']== 1)
                            BrnTagCustom.buildBorderTag(
                              tagText: '审核中',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(userMap['trailerDrivingLicenseStatus']== 2)
                            BrnTagCustom.buildBorderTag(
                              tagText: '已认证',
                              textColor: Colors.green,
                              borderColor: Colors.green,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                        ],
                      ),

                      GestureDetector(
                        child: Text("编辑",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                        onTap: () async {
                          final result=await Navigator.push( context, FadeRoute(page:EditTrailerCard(dataMap: userMap,)));
                          if(result!=null){
                            getUserMessage();
                          }
                        },
                      )
                    ],
                  )
                      :Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+messages["挂车行驶证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ],
                  ),
                  SizedBox(height: 12.h,),
                  Divider(color: Color.fromRGBO(240, 240, 240, 1),),
                  SizedBox(height: 12.h,),
                  userMap['trailerDrivingLicenseInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+userMap['trailerDrivingLicenseInfo']['vehicleNum'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    ],
                  )
                      :GestureDetector(
                    child: Container(
                      width: 200.w,
                      height: 40.h,
                      decoration: BoxDecoration(
                        color: Color.fromRGBO(231, 112, 27, 0.85),
                        borderRadius: BorderRadius.all(Radius.circular(60)),
                      ),
                      child:Center(
                        child:Text("+"+messages["添加挂车行驶证"],style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600),),
                      ),
                    ),
                    onTap: ()async{
                      final result=await Navigator.push( context, FadeRoute(page:EditTrailerCard(dataMap: userMap,)));

                      if(result!=null){
                        getUserMessage();
                      }
                    },
                  ),

                  SizedBox(height: 12.h,),
                ],
              ),
            ),
          ),

          SizedBox(height: 8.h,),
          GestureDetector(
            onTap: ()async{
              final result=await Navigator.push( context, FadeRoute(page:EditRoadCard(dataMap: userMap,)));

              if(result!=null){
                getUserMessage();
              }
            },
            child: Container(
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              padding: EdgeInsets.only(right: 12.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Column(
                children: [
                  SizedBox(height: 12.h,),
                  userMap['roadTransportCertificateInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("    "+messages["道路运输证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                          SizedBox(width: 4.w,),
                          if(userMap['roadTransportCertificateInfo']['expiryDate']!=""&&(compareDateWithCurrent(userMap['roadTransportCertificateInfo']['expiryDate'])=="2"||compareDateWithCurrent(userMap['vehicleDrivingLicenseInfo']['scrapDate'])=="3"))
                            BrnTagCustom.buildBorderTag(
                              tagText: '即将过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(userMap['roadTransportCertificateInfo']['expiryDate']!=""&&compareDateWithCurrent(userMap['roadTransportCertificateInfo']['expiryDate'])=="4")
                            BrnTagCustom.buildBorderTag(
                              tagText: '已过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(userMap['roadTransportCertificateStatus']== 1)
                            BrnTagCustom.buildBorderTag(
                              tagText: '审核中',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(userMap['roadTransportCertificateStatus']== 2)
                            BrnTagCustom.buildBorderTag(
                              tagText: '已认证',
                              textColor: Colors.green,
                              borderColor: Colors.green,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                        ],
                      ),
                      GestureDetector(
                        child: Text("编辑",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                        onTap: () async {
                          final result=await Navigator.push( context, FadeRoute(page:EditRoadCard(dataMap: userMap,)));

                          if(result!=null){
                            getUserMessage();
                          }
                        },
                      )
                    ],
                  )
                      :Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+messages["道路运输证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ],
                  ),
                  SizedBox(height: 12.h,),
                  Divider(color: Color.fromRGBO(240, 240, 240, 1),),
                  SizedBox(height: 12.h,),
                  userMap['roadTransportCertificateInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+userMap['roadTransportCertificateInfo']['licenceNum'],style: TextStyle(color: Colors.black,fontSize: 14.sp,),),
                    ],
                  )
                      :GestureDetector(
                    child: Container(
                      width: 200.w,
                      height: 40.h,
                      decoration: BoxDecoration(
                        color: Color.fromRGBO(231, 112, 27, 0.85),
                        borderRadius: BorderRadius.all(Radius.circular(60)),
                      ),
                      child:Center(
                        child:Text("+"+messages["添加道路运输证"],style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                      ),
                    ),
                    onTap: ()async{
                      final result=await Navigator.push( context, FadeRoute(page:EditRoadCard(dataMap: userMap,)));
                      if(result!=null){
                        getUserMessage();
                      }
                    },
                  ),

                  SizedBox(height: 12.h,),
                ],
              ),
            ),
          ),

          SizedBox(height: 8.h,),
          GestureDetector(
            onTap: ()async{
              final result=await Navigator.push( context, FadeRoute(page:EditQualification(dataMap: userMap,)));
              if(result!=null){
                getUserMessage();
              }
            },
            child:  Container(
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              padding: EdgeInsets.only(right: 12.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Column(
                children: [
                  SizedBox(height: 12.h,),
                  userMap['qualificationCertificateInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [

                      Row(
                        children: [
                          Text("    "+messages["从业资格证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                          SizedBox(width: 4.w,),
                          if(compareDateWithCurrent(userMap['qualificationCertificateInfo']['expiryDate'])=="2"||compareDateWithCurrent(userMap['qualificationCertificateInfo']['expiryDate'])=="3")
                            BrnTagCustom.buildBorderTag(
                              tagText: '即将过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(compareDateWithCurrent(userMap['qualificationCertificateInfo']['expiryDate'])=="4")
                            BrnTagCustom.buildBorderTag(
                              tagText: '已过期',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          SizedBox(width: 4.w,),
                          if(userMap['qualificationCertificateStatus']== 1)
                            BrnTagCustom.buildBorderTag(
                              tagText: '审核中',
                              textColor: Colors.red,
                              borderColor: Colors.red,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                          if(userMap['qualificationCertificateStatus']== 2)
                            BrnTagCustom.buildBorderTag(
                              tagText: '已认证',
                              textColor: Colors.green,
                              borderColor: Colors.green,
                              borderWidth: 1,
                              fontSize: 9.sp,
                              textPadding: EdgeInsets.all(1),
                            ),
                        ],
                      ),

                      GestureDetector(
                        child: Text("编辑",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                        onTap: () async {
                          final result=await Navigator.push( context, FadeRoute(page:EditQualification(dataMap: userMap,)));
                          if(result!=null){
                            getUserMessage();
                          }
                        },
                      )
                    ],
                  )
                      :Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+messages["从业资格证信息"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ],
                  ),
                  SizedBox(height: 12.h,),
                  Divider(color: Color.fromRGBO(240, 240, 240, 1),),
                  SizedBox(height: 12.h,),
                  userMap['qualificationCertificateInfo']!=null?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text("    "+userMap['qualificationCertificateInfo']['qualificationCertificate'],style: TextStyle(color: Colors.black,fontSize: 14.sp,),),
                    ],
                  )
                      :GestureDetector(
                    child: Container(
                      width: 200.w,
                      height: 40.h,
                      decoration: BoxDecoration(
                        color: Color.fromRGBO(231, 112, 27, 0.85),
                        borderRadius: BorderRadius.all(Radius.circular(60)),
                      ),
                      child:Center(
                        child:Text("+"+messages["添加从业资格证"],style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                      ),
                    ),
                    onTap: ()async{
                      final result=await Navigator.push( context, FadeRoute(page:EditQualification(dataMap: userMap,)));
                      if(result!=null){
                        getUserMessage();
                      }
                    },
                  ),

                  SizedBox(height: 12.h,),
                ],
              ),
            ),
          ),

        ],

      ),
          ),
    );


  }
}
